#Include ..\baseHandle.ahk
#Include ..\..\_lib\RunCMD.ahk

class GetVar extends BaseHandle {

  static Handle(parsed) {
    mcf := MeowConf.Of('./cfg/misc/get.txt')
    val := mcf.Get(parsed.target)
    if !val
      return this.Fail('no var.')
    type := val.type, cmd := val.cmd
    res := type = 'psl' ? _RunPsl(cmd) : _RunCmd(cmd)
    return this.Succ(res)

    _RunCmd(cmd) => RunCMD(A_ComSpec ' ' cmd)
    _RunPsl(cmd) => RunCMD('powershell -Command ' cmd)

  }

  static Spec() {
    return {
      cmd: 'get',
      desc: '获取值',
      format: 'get <target>',
      args: {
        desc: '',
        isOptional: false,
        cacheable: true,
        fixed: true,
        generator: {
          script: '',
          postProcess: (*) => MeowConf.Of('./cfg/misc/get.txt').data.keys
        }
      },
      extra: {
        isEnable: true,
        desc: '值'
      }
    }
  }
}